package com.sttk.secreconeclick.bookkeep.dialog;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.blankj.utilcode.util.TimeUtils;
import com.contrarywind.adapter.WheelAdapter;
import com.contrarywind.view.WheelView;
import com.lzb.basic.dialog.BaseSmartDialog;
import com.lzb.basic.utils.SPUtil;
import com.sttk.secreconeclick.bookkeep.Content;
import com.sttk.secreconeclick.bookkeep.R;
import com.sttk.secreconeclick.bookkeep.databinding.DialogChangeCycleBinding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class ChangeCycleDialog extends BaseSmartDialog<DialogChangeCycleBinding> implements View.OnClickListener {


    public ChangeCycleDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_change_cycle;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.llMonth.setOnClickListener(this);
        mDataBinding.llYear.setOnClickListener(this);
        mDataBinding.llAll.setOnClickListener(this);

        clearSelection();
        int pos = SPUtil.getInt(getContext(), Content.cycle, 0);
        switch (pos) {
            case 0:
                mDataBinding.ivMonthSel.setImageResource(R.drawable.yes);
                break;
            case 1:
                mDataBinding.ivYearSel.setImageResource(R.drawable.yes);
                break;
            case 2:
                mDataBinding.ivAllSel.setImageResource(R.drawable.yes);
                break;
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        clearSelection();
        if (id == R.id.llMonth) {
            mDataBinding.ivMonthSel.setImageResource(R.drawable.yes);
            dismiss();
            if (listener != null) {
                listener.clickItem(0);
            }
        } else if (id == R.id.llYear) {
            mDataBinding.ivYearSel.setImageResource(R.drawable.yes);
            dismiss();
            if (listener != null) {
                listener.clickItem(1);
            }
        } else if (id == R.id.llAll) {
            mDataBinding.ivAllSel.setImageResource(R.drawable.yes);
            dismiss();
            if (listener != null) {
                listener.clickItem(2);
            }
        }
    }

    private void clearSelection() {
        mDataBinding.ivMonthSel.setImageResource(R.drawable.no);
        mDataBinding.ivYearSel.setImageResource(R.drawable.no);
        mDataBinding.ivAllSel.setImageResource(R.drawable.no);
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickItem(int pos);
    }
}
